<?
	class Company extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->model('CompanyModel');
		}
		private final function showView($fileName, $data)
		{
			$l = $this->load;
			$l->view('Templates/header.php', $data);
			$l->view('Companies/' . $fileName . '.php', $data);
			$l->view('Templates/footer.php', $data);
		}
		private final function getPostData()
		{
			$i = $this->input;
			$b = $this->CompanyModel;
			$b->Id = $i->post('id');
			$b->Name = $i->post('name');
			$b->Type = $i->post('type');
			$b->Website = $i->post('website');
			$b->Landline = $i->post('landline');
			$b->Mobile = $i->post('mobile');
			$b->Fax = $i->post('fax');
			$b->Email = $i->post('email');
			$b->Address = $i->post('address');
			return $b;
		}
		public final function create()
		{
			$data['title'] = 'Add a company';
			$data['company'] = $this->CompanyModel->addCompany($this->getPostData());
			$this->showView('create', $data);
		}
		public final function read($id = null)
		{
			if($id == null)
			{
				$data['title'] = 'View all companies';
				$data['companies'] = $this->CompanyModel->getAllCompanies();
			}
			else
			{
				$data['title'] = 'View company details';
				$data['companies'] = $this->CompanyModel->getCompanyById($id);
			}
			$this->showView('read', $data);
		}
		public final function update()
		{
			$data['title'] = 'Update a company';
			$data['company'] = $this->CompanyModel->updateCompany($this->getPostData());
			$this->showView('update', $data);
		}
		public final function delete()
		{
			$id = $this->input->post('id');
			$data['title'] = 'Remove a company';
			$data['company'] = $this->CompanyModel->removeCompanyById($id);
			$this->showView('delete', $data);
		}
		public final function donate()
		{
			$p = $this->input->post;
			//Submit POST data to Ngo through AJAX.
		}
	}